//package com.office.personalOffice.personalInfo.service.impl;
//
//import com.office.personalOffice.personalInfo.dao.IPersonalInfo;
//import com.office.personalOffice.personalInfo.model.LoginUser;
//import com.office.personalOffice.personalInfo.model.TbStaff;
//import com.office.util.JwtUtil;
//import com.office.util.RedisCache;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.stereotype.Service;
//
//import javax.servlet.http.HttpSession;
//import java.util.Objects;
//
///**
// *
// */
//@Service
//public class UserDetailsServiceImpl implements UserDetailsService {
//
//    @Autowired
//    private IPersonalInfo userMapper;
//    @Autowired
//    private RedisCache redisCache;
//    @Override
//    public UserDetails loadUserByUsername(String username)  {
//        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
//        //根据用户名查询用户信息
//        TbStaff login = userMapper.login(username);
//        //如果查询不到数据就通过抛出异常来给出提示
//        if(Objects.isNull(login)){
//          return new LoginUser(null);
//        }
//        //使用userid生成token
//        String userId = login.getId().toString();
//        String jwt = JwtUtil.createJWT(userId);
//        //authenticate存入redis
//        redisCache.setCacheObject("login:"+userId,jwt);
//        //TODO 根据用户查询权限信息 添加到LoginUser中
//
//        //封装成UserDetails对象返回
//        return new LoginUser(login);
//    }
//}